package com.example

/**
 * 习惯用法
 * Created by Walkud on 17/8/21.
 */
object CustomerUse {

    /**
     * 构建实体类
     * 会提供以下功能
     * 所有属性的getters（对于var定义会提供setters）
     * equals()
     * hashCode()
     * toString()
     * copy()
     * 所有属性的componentN
     */
    data class Customer(val name: String, val email: String)

    data class Cat(val name: String = "波斯猫", val email: String = "xxx@163.com") {

        fun print() {
            println(toString())
        }
    }

    @JvmStatic
    fun main(array: Array<String>) {
        val customer = Customer("花生", "花生123@qq.com")

        println(customer.toString())

        typeWhen(customer)
        typeWhen(Cat())

    }

    /**
     * 使用when与is对类型进行判断
     */
    fun typeWhen(obj: Any) {
        when (obj) {
            is Customer -> println(obj.toString())
            is Cat -> obj.print()
        }
    }


}